Re: [INTERFACES] libpq & user - Mailing list pgsql-interfaces

From Herouth Maoz
Subject Re: [INTERFACES] libpq & user
Date
Msg-id l03110704b1d220f2ec4a@[147.233.159.109]
Whole thread Raw
In response to libpq & user  (Robert Knop <rknop@panisse.lbl.gov>)
Responses Re: [INTERFACES] libpq & user  (Robert Knop <rknop@panisse.lbl.gov>)
List pgsql-interfaces
At 0:02 +0300 on 15/7/98, Robert Knop wrote:


> I'm trying to use libpq to read a Postgres database from C.  I use the
> following command to connect to the database:
>
>   PGconn *deep;
>   deep=PQsetdb("dara",NULL,"user=deep",NULL,"deep");

I didn't exactly get it from your problem description, but I take it that
putting the username in the options field doesn't work.

Well, two alternatives for solution:

In the psql source code, they set the user by setting the PGUSER
environment variable. The source of the PQsetdb function states that the
following environment variables are accepted (although this is not
documented - at least not in my old 6.2.1 version):

PGHOST, PGPORT, PGTTY, PGOPTIONS, PGUSER, PGPASSWORD, PGDATABASE

So you may set these variables from within your program or from the shell
script that calls it.

Another option: the psql source, when needing a password, uses the
undocumented function:

PQconnectdb( connection_string );

The connection string is a C character string containing pairs of names and
values. For example: "host=dara user=deep password=ocean dbname=deep".

The allowed parameters are:
host, port, tty, options, user, password, authtype, dbname

Which to use? Depends on which undocumented feature you prefer... Or maybe
the gurus who actually wrote the code can give us a hint.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



pgsql-interfaces by date:

Previous
From: Ewan Mellor
Date:
Subject: Non-blocking queries using libpq
Next
From: Byron Nikolaidis
Date:
Subject: Re: [INTERFACES] [ODBC support]